import { HttpStatus } from '@nestjs/common';
import { Axios, AxiosRequestConfig } from 'axios';
import axios from 'axios'
const actionBuilder = (axiosConfig?: AxiosRequestConfig) => {
  const action = axios.create(axiosConfig);
  action.interceptors.request.use(
    (config) => {
      return config;
    },
    (error) => {
      return Promise.reject(error);
    },
  );
  action.interceptors.response.use(
    (res) => {
      if (res.status == HttpStatus.OK) {
        if (res.data.code === 200) {
          return Promise.resolve(res.data.data);
        }
        return Promise.reject(res.data.message);
      }
      return Promise.reject(res);
    },
    (error) => {
      return Promise.reject(error);
    },
  );

  return action.request;
};

export default actionBuilder;
